<?php
class CatIndexModel extends Model
{
    public function getNewsList($catId,$page = 0)
    {
        /*$this->loadTable('post');
        return $this->tables['post']->get(array('category_id' => $catId,'status' => 1),array('limit' => 5,'offset' => ($page * 5)));*/
        $db = DataProvider::getInstance();
        $session = Session::getInstance();
        $this->loadTable('category');
        $this->loadTable('post');
        $rs = $this->tables['category']->get(array('parent_id' => $catId));
        if($rs->getSize() == 0)
        {
            return $this->tables['post']->get(array('category_id' => $catId,'status' => 1),array('limit' => 5,'offset' => ($page * 5),'order' => array('p_date' => 'DESC')));
        }
        else
        {
            $sql = "select * from post where category_id in (";
            $size = $rs->getSize();
            $row = $rs->getRow(0);
            $sql .= $row->id;
            for($i = 1;$i < $size;$i++)
            {
                $row = $rs->getRow($i);
                $sql .= "," . $row->id;
            }
            $sql .= ") AND STATUS= 1 ORDER BY p_date DESC LIMIT " . ($page * 5) . ",5";
            return $db->_query($sql);
        }
    }

    public function getLastestAlbum()
    {
        $this->loadTable('album');
        $this->loadTable('item');
        $rs = $this->tables['album']->get(array('status' => 2));
        //        var_dump($rs);exit();
        $row = $rs->getRow(0);
        $rs2 = $this->tables['item']->get(array('album_id' => $row->id));
        return $rs2;
    }
}